<?php

include_once($cfgPaths['lib/dba'].'dbaCategory.o.inc.php');
include_once($cfgPaths['lib/dba'].'categoryTable.o.inc.php');

class dbaUnCategory extends dbaCategory{
  
  function getUCategoriesArray(&$result){
    $check  = $this->query("select * from ".$this->tableforwarder."_unCat order by name;");
    $result = $this->fetch_rows_array();
    return $check;
  }

  function getUCategoryByID(&$result,$id){
    $check  = $this->query("select * from ".$this->tableforwarder."_unCat where id=$id;");
    $result = $this->fetch_row_array();
    return $check;
  }

  function getUCategoriesArrayFields(&$result,$fields){
    $count = count($fields);
    for ($i = 0; $i < $count; $i++){
      if ($i == $count-1){
        $fieldStr .= $fields[$i];
      } else {
        $fieldStr .= $fields[$i].",";
      }
    }
    $check  = $this->query("select $fieldStr from ".$this->tableforwarder."_unCat order by name;");
    $result = $this->fetch_rows_array();
    return $check;
  }

  function getUCategoriesObj(&$check){
    $this->getUCategoriesArray($result);
    return new categoryTable($result);
  }

  function getUCategoriesObjFields(&$check,$fields){
    $this->getUCategoriesArrayFields($result,$fields);
    return new categoryTable($result);
  }
  
  function addUCategory($parent_id,$name,$display_url){
    return $this->query("insert into ".$this->tableforwarder."_unCat (name,top,display_url) values('$name',$parent_id,'$display_url');");
  }

  function updateUCategoryName($id,$name,$display_url){
    return $this->query("update ".$this->tableforwarder."_unCat set name='$name', display_url='$display_url' where id = $id;");
  }

  function updateUCategoryParent($id,$parent){
    return $this->query("update ".$this->tableforwarder."_unCat set top=$parent where id = $id;");
  }
  
  function delUCategory($id){
    return $this->query("delete from ".$this->tableforwarder."_unCat where id=$id;");
  }

}
?>
